home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / src / p8bitblt.c < prev    next >
Text File  |  1993-12-06  |  4KB  |  107 lines

  1. /**
  2.  ** P8BITBLT.C
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #include "p8.h"
  25. #include "memcopy.h"
  26. #include "gmalloc.h"
  27.  
  28. void _GrP8PixCopy(GC *dst,long daddr,GC *src,long saddr,int w,int h,int op)
  29. {
  30.     pixptr dstp = P_ADDRESS(dst,daddr);
  31.     pixptr srcp = P_ADDRESS(src,saddr);
  32.     pixptr temp;
  33.     int doff = dst->gc_lineoffset - w;
  34.     int soff = src->gc_lineoffset - w;
  35.     int bytecpy = ((int)daddr | (int)saddr | doff | soff | w) & 1;
  36.     int copywdt = w >> (bytecpy ^ 1);
  37.     int reverse = FALSE;
  38.  
  39.     if((w <= 0) || (h <= 0)) return;
  40.     op = C_OPER(op);
  41.     _ClrDir();
  42.     if(_GrP8UsePlanarMode) PLANAR_MODE_OFF();
  43.     if((dst->gc_baseaddr == src->gc_baseaddr) && (daddr > saddr)) {
  44.         dstp += (unsigned)((h * dst->gc_lineoffset) - doff - 2 + bytecpy);
  45.         srcp += (unsigned)((h * src->gc_lineoffset) - soff - 2 + bytecpy);
  46.         doff = (-doff);
  47.         soff = (-soff);
  48.         reverse = TRUE;
  49.         _SetDir();
  50.     }
  51.     if(dst->gc_onscreen && src->gc_onscreen && _GrBigFrameBuffer) {
  52.         if(_GrCanBcopyInBlit && (op == C_SET)) {
  53.         dstp += _GrWrOnlyOffset;
  54.         srcp += _GrRdOnlyOffset;
  55.         }
  56.         else {
  57.         temp = (pixptr)_GrGetTempBuffer(w + 2);
  58.         if(temp == (pixptr)NULL) return;
  59.         if(reverse) { temp += w; w = (-w); }
  60.         doff += w;
  61.         soff += w;
  62.         _SaveDS();
  63.         if(bytecpy) while(--h >= 0) {
  64.             _RowCpyB(RB,temp,srcp,copywdt);
  65.             switch(op) {
  66.             case C_XOR: _RowCpyXorB(WBX,dstp,temp,copywdt); break;
  67.             case C_OR:  _RowCpyOrB(WBO,dstp,temp,copywdt);  break;
  68.             case C_AND: _RowCpyAndB(WBA,dstp,temp,copywdt); break;
  69.             default:    _RowCpyB(WB,dstp,temp,copywdt);    break;
  70.             }
  71.             dstp += doff;
  72.             srcp += soff;
  73.         }
  74.         else while(--h >= 0) {
  75.             _RowCpyW(RW,temp,srcp,copywdt);
  76.             switch(op) {
  77.             case C_XOR: _RowCpyXorW(WWX,dstp,temp,copywdt); break;
  78.             case C_OR:  _RowCpyOrW(WWO,dstp,temp,copywdt);  break;
  79.             case C_AND: _RowCpyAndW(WWA,dstp,temp,copywdt); break;
  80.             default:    _RowCpyW(WW,dstp,temp,copywdt);    break;
  81.             }
  82.             dstp += doff;
  83.             srcp += soff;
  84.         }
  85.         _RestoreDS();
  86.         _ClrDir();
  87.         return;
  88.         }
  89.     }
  90.     _SaveDS();
  91.     if(bytecpy) switch(op) {
  92.         case C_XOR: _BlkCpyXorB(CBX,dstp,doff,srcp,soff,copywdt,h); break;
  93.         case C_OR:  _BlkCpyOrB(CBO,dstp,doff,srcp,soff,copywdt,h);  break;
  94.         case C_AND: _BlkCpyAndB(CBA,dstp,doff,srcp,soff,copywdt,h); break;
  95.         default:    _BlkCpyB(CB,dstp,doff,srcp,soff,copywdt,h);    break;
  96.     }
  97.     else switch(op) {
  98.         case C_XOR: _BlkCpyXorW(CWX,dstp,doff,srcp,soff,copywdt,h); break;
  99.         case C_OR:  _BlkCpyOrW(CWO,dstp,doff,srcp,soff,copywdt,h);  break;
  100.         case C_AND: _BlkCpyAndW(CWA,dstp,doff,srcp,soff,copywdt,h); break;
  101.         default:    _BlkCpyW(CW,dstp,doff,srcp,soff,copywdt,h);    break;
  102.     }
  103.     _RestoreDS();
  104.     _ClrDir();
  105. }
  106.  
  107.